#ifndef RTE_KT1282_SLAVE_RINGVECTOR_H
#define RTE_KT1282_SLAVE_RINGVECTOR_H

#include <Arduino.h>
#include <vector>
#include"mad.h"

using uint32_t = unsigned int;

template<typename data_type>
class RingVector {
public:
    int begin(uint32_t size);

    std::vector<data_type> buf;

    void store(data_type c);

    data_type value();

    uint32_t _size;
};

template<typename data_type>
int RingVector<data_type>::begin(uint32_t size) {
    _size = size;
    for (int i = 0; i < _size; i++) { buf.push_back(0); }
    return 0;
}

template<typename data_type>
void RingVector<data_type>::store(data_type c) {
    while (buf.size() >= _size) {
        buf.erase(buf.begin(), buf.begin() + 1);
    }
    buf.push_back(c);
}

template<typename data_type>
data_type RingVector<data_type>::value() {
    data_type v = Mad<uint32_t>(buf, 100);
    // data_type v =buf.back();
    return v;
}

#endif //RTE_KT1282_SLAVE_RINGVECTOR_H
